<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    @@ include("../../header.jsp"){} $$
    <!-- jqgrid-->
    <link href="/static/css/bootstrap.css?v=3.3.6" rel="stylesheet">
    <link href="/static/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/static/jqgrid/jqgrid.css" rel="stylesheet">
    <style>
        .ui-jqgrid-btable tbody tr td{
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
    <div class="content-search">
        <div style="padding:15px;">
            <form id="search" class="layui-form layui-form-pane" lay-filter="form">
                <div class="layui-inline">
                    <label class="layui-form-label">流程名称</label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" autocomplete="off" class="layui-input" onchange="search()">
                    </div>
                </div>
                <div class="layui-inline">
                    <btl:auth type="button" perm="biz:procDef:list" iconText="&#xe615;"
                               onclick="return search();" text=" 搜索"/>
                </div>
                <div class="layui-inline">
                    <btl:auth type="button" perm="biz:procDef:edit" iconText="&#xe654;" onclick="add()" text="部署流程"/>
                </div>
            </form>

        </div>
    </div>
        <!-- 内容主体区域 -->
    <div style="padding: 2px;">
        <div class="jqGrid_wrapper">
            <table id="table"></table>
            <div id="pager" ></div>
        </div>
    </div>
</div>
<script src="/static/jqgrid/i18n/grid.locale-cnffe4.js?0820"></script>
<script src="/static/jqgrid/jquery.jqGrid.minffe4.js?0820"></script>
<script src="/static/jqgrid/frozen.js?v=1.0.1"></script>
<script src="/static/jqgrid/myjqGrid.js"></script>
<script>

    layui.use('form', function(){
    });

    var colNames = ["ID","流程名称", "流程键", "流程版本","操作"];
    var colModel = [{
        name : "id",
        index : "id",
        width : 50,
        hidden: true,
        align : "left"
    },{
        name : "name",
        index : "name",
        sortable : false,
        editable : false,
        width : 150,
        align : "left"
    },{
        name : "key",
        index : "key",
        editable : false,
        width : 120,
        align : "left"
    },{
        name : "version",
        index : "version",
        editable : false,
        width : 50,
        align : "left"
    },{
        name : "action",
        index : "action",
        width : 150,
        title:false,
        editable:true,
        align : "center",
        formatter : function(cellvalue, options, rowdata){
            var html = '<btl:auth type="button" perm="biz:procDef:list" extClass="btn-view layui-bg-blue" iconText="&#xe60d;" dataId="' + rowdata.id + '" text="预览流程" />' +
                '<btl:auth type="button" perm="biz:procDef:delete" extClass="btn-del layui-bg-red" iconText="&#xe640;" dataId="' + rowdata.id + '" text="删除流程" />';
            return html;
        }
    }];

    var myJqGrid = null;
    $(document).ready(function () {
        myJqGrid = new MyJqGrid({
            jqGrid_id: 'table',
            data: "/pc/biz/procDef/list.json",
            isSubGrid: false,
            autowidth: true,
            shrinkToFit: true,
            autoScroll: true,
            colNames: colNames,
            colModel: colModel
        })
    });

    function search() {
        var name = $("#name").val();
        myJqGrid.reloadGrid({"name": name});
        return false;
    }

    function add() {
        layer.open({
            title: '部署流程',
            type: 2,
            area: ['500px', '450px'],
            content: '/pc/biz/procDef/edit'
        });
        return false;
    }

    $(function(){

        $(document).on("click", ".btn-view", function (e) {
            // var id = $(this).data("id");
            // var rowind = myJqGrid.jqGrid('getInd',id);
            // var key = myJqGrid.jqGrid('getCell',rowind, 'key');
            //
            // console.log(id);
            // console.log(key);
            window.open('/pc/biz/procDef/view?id='+$(this).data("id"));
            return;
            // layer.open({
            //     title: '预览流程',
            //     type: 2,
            //     area: ['500px', '350px'],
            //     content: '/pc/biz/procDef/view?id='+$(this).data("id")
            // });
        });

        $(document).on("click", ".btn-del", function (e) {
            var id = $(this).data("id");
            layer.confirm('确定删除该流程吗？会导致正在执行的任务也会删除', {
                icon: 3,
                btn: ['确定','取消'] //按钮
            }, function(){ //确定
                var params = {"id":id};
                console.log(id);
                $.post("/pc/biz/procDef/delete", params, function(data){
                    if(data.status == 0){
                        layer.alert(data.msg, {
                            icon: 1,
                            skin: 'layer-ext-moon'
                        },function () {
                            search();
                            layer.closeAll();
                        });
                    }else{
                        layer.alert(data.msg, {
                            icon: 2,
                            skin: 'layer-ext-moon'
                        });
                    }
                });
            }, function(){ //取消
            });
        });
    });

</script>
</body>
</html>